
// IMPORTS
import MASS.*;                  // MASS Library
import java.util.*;             // Vectors, etc.
import java.util.AbstractMap.*; // for simple key-value pairs
import java.util.logging.Level;
import java.util.logging.Logger;


public class MassMultiPlaces {
    // CONSTANTS - MASS arguments

    private static final String[] MASSARGS = {"dslab", "dslab-302",
        "machinefile.txt", "12345"};            // connection arguments
    private static final int NPROCESSES = 1;    // number of processes to employ
    private static final int NTHREADS = 8;      // number of threads to employ
    private static final int HANDLE = 0;        // unique Places handle number
    
    private static final int FOUR = 0;
    private static final  int NINE = 1;
    // CONSTANTS - Functions
    Place four;
    Place nine;

    public static void main(String[] args) {

        try {
            MASS.init(MASSARGS, NPROCESSES, NTHREADS);
            Object[] fixer = new Object[4];
            Object[] fixer2 = new Object[9];

            Places four, nine;
//            MassFour test = new MassFour(null);
            four = new Places(FOUR, "MassFour", null, 4);
            nine = new Places(NINE, "MassNine", null, 9);

////            Places nine = new Places(1, "MassNine", null, 9);
//            
//                        
            four.callAll(0, fixer);
            nine.callAll(0, fixer2);
           

            int[] dests = {0};
            Vector<int[]> neighbor = new Vector();
            neighbor.add(dests);
            
            // Call nine, pass four's handle
//            nine.exchangeAll(FOUR, 1, neighbor);
//            Thread.sleep(1000);
//            nine.callAll(2, fixer2);

            // Call four, pass nine's handle
            four.exchangeAll(NINE, 1, neighbor);
            Thread.sleep(1000);
            nine.callAll(2, fixer2);

            // Call nine, pass nine's handle
//            nine.exchangeAll(1, 1, neighbor);
//            Thread.sleep(1000);
//            nine.callAll(2, fixer2);

            // Call four, pass four's handle
//            four.exchangeAll(0, 1, neighbor);
//            Thread.sleep(1000);
//            nine.callAll(2, fixer2);

            MASS.finish();
        } catch (Exception ex) {
            Logger.getLogger(MassMultiPlaces.class.getName()).log(Level.SEVERE, null, ex);
        } finally {
        }
    }
}
